package cloud.maque.admin.controller;

import cloud.maque.admin.domain.entity.MqXzqChange;
import cloud.maque.admin.service.MqXzqChangeService;
import cloud.maque.framework.common.request.PaginateDataResquest;
import cloud.maque.framework.common.response.ResponseBodyVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 行政区
 *
 * @author zhuyf
 * @date 2022/6/28 15:52
 */
@RestController
@RequestMapping("/xzq/change")
@RefreshScope //自动刷新nacos配置
@Api(value = "组件-行政区变化", tags = "组件-行政区变化")
public class XzqChangeController {

    @Autowired
    MqXzqChangeService compXzqChangeService;


    /**
     * 行政区列表
     *
     * @return
     * @ignore
     */
    @PostMapping("/list")
    public ResponseBodyVo<PageInfo<List<MqXzqChange>>> XzqChangeAllList(@RequestBody PaginateDataResquest<MqXzqChange> queryRequest) {
        PageInfo<List<MqXzqChange>> result = compXzqChangeService.listByPage(queryRequest);
        return ResponseBodyVo.Success("成功", result);
    }


    /**
     * 民政时间列表
     *
     * @return
     * @ignore
     */
    @PostMapping("/mcmlist")
    public ResponseBodyVo<List<String>> XzqMcmList() {
        List<String> result = compXzqChangeService.listMcmtime();
        return ResponseBodyVo.Success("成功", result);
    }


    @ApiOperation(value = "根据行政区代码获取变化")
    @PostMapping("/listchange/{xzq}")
    public ResponseBodyVo<List<MqXzqChange>> XzqChangeList(@PathVariable("xzq") @ApiParam("行政区代码") String xzq) {
        List<MqXzqChange> result = compXzqChangeService.listByXzq(xzq);
        return ResponseBodyVo.Success("成功", result);
    }


    /**
     * 保存行政区
     *
     * @return
     * @ignore
     */
    @PostMapping("/save")
    public ResponseBodyVo<MqXzqChange> Save(@RequestBody MqXzqChange xzq) {
        MqXzqChange result = compXzqChangeService.Save(xzq);
        return ResponseBodyVo.Success("保存成功", result);
    }


    /**
     * 删除行政区
     *
     * @return
     * @ignore
     */
    @PostMapping("/delete/{changeId}")
    public ResponseBodyVo<Boolean> Delete(@PathVariable("changeId") String changeId) {
        Boolean result = compXzqChangeService.Delete(changeId);
        return ResponseBodyVo.Success("删除成功", result);
    }

}
